home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / comm / bbs / cit_src_AD08.lha / save_msgout.c < prev    next >
C/C++ Source or Header  |  1997-08-17  |  19KB  |  819 lines

  1. /*
  2. *                               msgout.c
  3. *
  4. * External Message writer.  For use with external OtherNet parsers.
  5. */
  6. /*
  7. *                               history
  8. *
  9. * 92Jan17 HAW  1.4 - Hard-wire room name to msgs; handle domain field.
  10. * 91Mar26 HAW  1.3 - Virtual rooms.
  11. * 89Sep25 HAW  1.2 - update for Route Mail.
  12. * 88Nov17 HAW  Created.
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "ctdl.h"
  17. #include "2ndfmt.h"
  18. #include "stdarg.h"
  19. #include "dos.h"
  20. #include "math.h"
  21. /*
  22. *                               contents
  23. *
  24. */
  25. #define TITLE           "C86Net Message Exporter "
  26. #define NO_ERROR        0
  27. #define BAD_ARGS        1
  28. #define BAD_TABLE       2
  29. #define NO_NODE         3
  30. #define FATAL           4
  31. #define BAD_OUT_FILE    5
  32. #define LF_ERROR        6
  33.  
  34. char onConsole=1, remoteSysop;
  35. char netDebug='\0';
  36.  
  37. FILE            *outfile;
  38. extern FILE *upfd;
  39. extern CONFIG      cfg;                 /* Configuration variables      */
  40. extern MessageBuffer msgBuf;    /* The -sole- message buffer    */
  41. extern aRoom       roomBuf;             /* Room buffer */
  42. extern logBuffer   logBuf;
  43. extern FILE        *roomfl, *logfl;
  44. extern int         thisRoom;    /* Current room    */
  45. extern rTable      *roomTab;
  46. extern struct mBuf mFile1, mFile2;
  47. extern SListBase Serves;
  48. extern NetTable    *netTab;
  49. extern NetBuffer   netBuf, netTemp;
  50. extern FILE        *netfl;
  51. extern LogTable    *logTab;
  52. extern FILE        *msgfl, *msgfl2;
  53. FILE       *GlobalFd, *netMisc;
  54. static int RCount, SCount;
  55. extern int         thisNet;        /* Current node in use          */
  56. char *R_SH_MARK =  "&&";
  57. char *NON_LOC_NET= "%%";
  58. char *LOC_NET =    "++";
  59. char inNet = ANYTIME_NET;
  60.  
  61. void NetField(int field, char *value);
  62. void MsgOutGenInit(void);
  63. void MODoVirtuals(void);
  64. void Process(void);
  65. int  FindNet(label nm);
  66. int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  67. char *room);
  68. void UtilRoomSend(int rover, char *send1, char *send2, char *send3);
  69. void HandleMessage(char *addr1, char *addr2, char *addr3);
  70. int  RoutePath(char *rp, char *str);
  71. char FindMessage(SECTOR_ID loc, MSG_NUMBER id);
  72. void NetFormat(void);
  73. void NowRouteMail(void);
  74. void MoutCC(char *);
  75. void MoutForeign(char *);
  76. void NowDomainMail(void);
  77. char HandleMail(int net, NetBuffer *nbuf);
  78. void Intel32ToMotorola(UNS_32 *);
  79. char *formDate(void);
  80. char *Current_Time(void);
  81.  
  82. typedef struct
  83.   {
  84.   char (*fn)();
  85.   int count;
  86.   char lc;
  87.   } DO_Args;
  88.  
  89. int UtilDomainOut(char (*f)(char *name, char *domain, char LocalCheck),
  90.                         char LocalCheck);
  91. void *CheckDomain(void *);
  92. void *EatDomainLine(char *line);
  93. int CmpDomain();
  94.  
  95. extern SListBase DomainMap;
  96.  
  97.  
  98. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  99.  
  100. /**
  101.   some statistics
  102. **/
  103. int total_msgs = 0;  /* total messages output */
  104.  
  105. /*
  106. * crashout()
  107. *
  108. * Crash exit handler.
  109. */
  110. void crashout(str)
  111. char *str;
  112.   {
  113.   printf(str);
  114.   writeSysTab();
  115.   exit(FATAL);
  116.  
  117.   }
  118. FILE *netLog = stderr;
  119.  
  120. /*
  121. * main()
  122. *
  123. * Main manager
  124. */
  125. int  main(int, char **);
  126. int  main(argc, argv)
  127. char **argv;
  128. int  argc;
  129.   {
  130.   extern char *WRITE_ANY;
  131.   printf("%s %s\n%s\n\n", TITLE, VERSION_NAME, COPYRIGHT);
  132.   /* not enough arguments?  Explain. */
  133.   if (argc < 3)
  134.     {
  135.     printf("usage: MSGOUT nodename file\n");
  136.     exit(BAD_ARGS);
  137.  
  138.     }
  139.   cfg.weAre = UTILITY;
  140.   if (!readSysTab(TRUE, TRUE))
  141.     {
  142.     exit(BAD_TABLE);
  143.  
  144.     }
  145.   if (access(LOCKFILE, 0) != ERROR)
  146.     {
  147.     printf("Please do not run MsgOut using Outside Commands.\n");
  148.     exit(LF_ERROR);
  149.  
  150.     }
  151.   MsgOutGenInit();
  152.   VirtInit();
  153.   DomainInit(TRUE);
  154.  
  155.   if (FindNet(argv[1]) == ERROR)
  156.     {
  157.     writeSysTab();
  158.     printf("Could not find node %s.\n", argv[1]);
  159.     exit(NO_NODE);
  160.  
  161.     }
  162.   if ((outfile = fopen(argv[2], WRITE_ANY)) == NULL)
  163.     {
  164.     writeSysTab();
  165.     printf("Couldn't open output file %s.\n", argv[2]);
  166.     exit(BAD_OUT_FILE);
  167.  
  168.     }
  169.   Process();
  170.   putNet(thisNet, &netBuf);
  171.   RationalizeDomains();
  172.   writeSysTab();
  173.   printf(" %d total messages output\n", total_msgs);
  174.   return 0;
  175.   }
  176. /*
  177. * MsgOutGenInit()
  178. *
  179. * This handles general initialization.
  180. */
  181. void MsgOutGenInit()
  182.   {
  183.   SYS_FILE fn;
  184.   initNetBuf(&netBuf);
  185.   initNetBuf(&netTemp);
  186.   makeSysName(fn, "ctdlnet.sys", &cfg.netArea);
  187.   openFile(fn, &netfl);
  188.   initRoomBuf(&roomBuf);
  189.   makeSysName(fn, "ctdlroom.sys", &cfg.roomArea);
  190.   openFile(fn, &roomfl);
  191.   InitMsgBase();
  192.  
  193.   }
  194. /*
  195. * Process()
  196. *
  197. * This is the main processor.
  198. */
  199. void Process()
  200.   {
  201.   char          *send1, *send2, *send3;
  202.   int                   rover;
  203.   extern char           *READ_ANY;
  204.  
  205.   splitF(netLog, "\nMsgOut Session\n");
  206.   splitF(netLog, "Working on %s @ %s\nStabilized\n", netBuf.netName, netBuf.netId);
  207.  
  208.   /* first we handle Mail>. */
  209.  
  210.   HandleMail(thisNet, &netBuf);
  211.  
  212.   NowRouteMail();               /* now handle any route mail */
  213.  
  214.   NowDomainMail();              /* Normal domain mail */
  215.   /* now we handle the shared rooms */
  216.   for (rover = 0; rover < SHARED_ROOMS; rover++)
  217.     {
  218.     /* if we share this room, check for new msgs. */
  219.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  220.       {
  221.       getRoom(netRoomSlot(rover));
  222.       send1 = R_SH_MARK;
  223.       send2 = send3 = "guh";
  224.       switch (roomBuf.rbShareType)
  225.         {
  226.         case REG_HOST:
  227.         printf("WARNING: Please do not use Regional Host settings.\n");
  228.         printf("\nThey are obsolete.\n");
  229.         case PEON:
  230.         break;
  231.         case BACKBONE:
  232.         switch (netBuf.netRooms[rover].mode)
  233.           {
  234.           case PEON:
  235.           send2  = NON_LOC_NET;
  236.           break;
  237.           case ACTIVE_BACKBONE:
  238.           case PASS_BACKBONE:
  239.           case REG_HOST:
  240.           send2 = NON_LOC_NET;
  241.           send3 = LOC_NET;
  242.           break;
  243.           default: crashout("shared rooms: #2");
  244.  
  245.           }
  246.         break;
  247.         default: crashout("shared rooms: #1");
  248.  
  249.         }
  250.       UtilRoomSend(rover, send1, send2, send3);
  251.  
  252.       }
  253.  
  254.     }
  255.   MODoVirtuals();
  256.   UpdVirtStuff();
  257.  
  258.   }
  259. /*
  260. * UtilRoomSend()
  261. *
  262. * Send stuff out.
  263. */
  264. void UtilRoomSend(rover, send1, send2, send3)
  265. int rover;
  266. char *send1, *send2, *send3;
  267.   {
  268.   int i;
  269.   for (i = 0; i < MSGSPERRM; i++)
  270.     {
  271.     if (roomBuf.msg[i].rbmsgNo > netBuf.netRooms[rover].lastMess)
  272.       {
  273.       if (FindMessage(roomBuf.msg[i].rbmsgLoc, roomBuf.msg[i].rbmsgNo))
  274.         {
  275.         strcpy(msgBuf.mbroom, roomBuf.rbname);
  276.         HandleMessage(send1, send2, send3);
  277.  
  278.         }
  279.  
  280.       }
  281.  
  282.     }
  283.   netBuf.netRooms[rover].lastMess = roomTab[thisRoom].rtlastMessage;
  284.   netTab[thisNet].netTRooms[rover].lastMess =
  285.   roomTab[thisRoom].rtlastMessage;
  286.  
  287.   }
  288. /*
  289. * HandleMessage()
  290. *
  291. * This decides if a message should be sent out.
  292. */
  293. void HandleMessage(addr1, addr2, addr3)
  294. char *addr1, *addr2, *addr3;
  295.   {
  296.   if ((strncmp(msgBuf.mbaddr, addr1, strLen(addr1)) == SAMESTRING  ||
  297.   strncmp(msgBuf.mbaddr, addr2, strLen(addr2))      == SAMESTRING  ||
  298.   strncmp(msgBuf.mbaddr, addr3, strLen(addr3))      == SAMESTRING) &&
  299.   RoutePath(LOC_NET, msgBuf.mbaddr)     != thisNet &&
  300.   RoutePath(NON_LOC_NET, msgBuf.mbaddr) != thisNet)
  301.     {
  302.     NetFormat();
  303.  
  304.     }
  305.  
  306.   }
  307. /*
  308. * RoutePath()
  309. *
  310. * This function returns the number of the node that routed this msg
  311. * to here.  If the msg was not routed in from a BackBone, then
  312. * return ERROR, which will never match another node's #.
  313. * 88Oct13: Now simply check for msg origin, assume if one exists
  314. * that it should be checked.  Don't remember why it is restricted
  315. * to only BACKBONE-routed msgs.  Doesn't seem necessary.
  316. */
  317. int RoutePath(rp, str)
  318. char *str, *rp;
  319.   {
  320.   if (strncmp(rp, str, strLen(rp)) == SAMESTRING)
  321.     {
  322.     if (strLen(str) != strLen(rp)) /* prevent return of 0 */
  323.     return atoi(str + 2);
  324.  
  325.     }
  326.   return ERROR;
  327.  
  328.   }
  329. /*
  330. * FindNet()
  331. *
  332. * This function will find the named node.  Stolen from searchNameNet/NETMISC.
  333. */
  334. int  FindNet(nm)
  335. label nm;
  336.   {
  337.   int rover;
  338.   for (rover = 0; rover < cfg.netSize; rover++)
  339.     {
  340.     if (netTab[rover].ntflags.in_use &&
  341.     hash(nm) == netTab[rover].ntnmhash)
  342.       {
  343.       getNet(rover, &netBuf);
  344.       if (strCmpU(netBuf.netName, nm) == SAMESTRING)
  345.       return rover;
  346.  
  347.       }
  348.  
  349.     }
  350.   return ERROR;
  351.  
  352.   }
  353. /*********** These functions stolen & modified from MSG.C ***************/
  354. /*
  355. * FindMessage()
  356. *
  357. * This gets all set up to do something with a message.  We use this rather
  358. * than the findMessage in libmsg.c so we can automatically read in the 'M'
  359. * field.
  360. */
  361. char FindMessage(loc, id)
  362. SECTOR_ID  loc;         /* sector in message.buf */
  363. MSG_NUMBER id;          /* unique-for-some-time ID# */
  364.   {
  365.   MSG_NUMBER here;
  366.   startAt(msgfl, &mFile1, loc, 0);
  367.   do
  368.     {
  369.     getMessage(getMsgChar, FALSE, TRUE, TRUE);
  370.     here = atol(msgBuf.mbId);
  371.  
  372.     }
  373.   while (here != id &&  mFile1.thisSector == loc);
  374.   return (char) ((here == id));
  375.  
  376.   }
  377. /*
  378. * NetFormat()
  379. *
  380. * This function writes a message to disk.
  381. */
  382. void NetFormat()
  383.   {
  384.   MSG_NUMBER val;
  385.   if (!msgBuf.mborig[0])
  386.   strCpy(msgBuf.mborig, cfg.nodeId + cfg.codeBuf);
  387.   if (!msgBuf.mboname[0])
  388.   strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  389.   if (!msgBuf.mbsrcId[0])
  390.     {
  391.     val = atol(msgBuf.mbId);
  392.     sPrintf(msgBuf.mbsrcId, "%ld %ld",
  393.     (val & 0xffff0000) >> 16, val & 0xffffl);
  394.  
  395.     }
  396.   if (msgBuf.mbauth[0])   NetField('A', msgBuf.mbauth);
  397.   if (msgBuf.mbdate[0])   NetField('D', msgBuf.mbdate);
  398.   if (msgBuf.mbtime[0])   NetField('C', msgBuf.mbtime);
  399.   if (msgBuf.mboname[0])  NetField('N', msgBuf.mboname);
  400.   if (msgBuf.mbdomain[0]) NetField('X', msgBuf.mbdomain);
  401.   if (msgBuf.mborig[0])   NetField('O', msgBuf.mborig);
  402.   if (msgBuf.mbroom[0])   NetField('R', msgBuf.mbroom);
  403.   if (msgBuf.mbsrcId[0])  NetField('S', msgBuf.mbsrcId);
  404.   if (msgBuf.mbto[0])     NetField('T', msgBuf.mbto);
  405.   if (msgBuf.mbOther[0])  NetField('P', msgBuf.mbOther);
  406.   RunList(&msgBuf.mbCC, MoutCC);
  407.   RunList(&msgBuf.mbForeign, MoutForeign);
  408.   NetField('M', msgBuf.mbtext);
  409.   total_msgs++;
  410.   }
  411. /*
  412. * NetField()
  413. *
  414. * Work function to write out a field and its identifier.
  415. */
  416. void NetField(int field, char *value)
  417.   {
  418.   fprintf(outfile, "%c%s", field, value);
  419.   putc(0, outfile);
  420.  
  421.   }
  422. /*
  423. * MoutCC()
  424. *
  425. * This handles the CC field of a message.
  426. */
  427. void MoutCC(char *dd)
  428.   {
  429.   NetField('W', dd);
  430.  
  431.   }
  432. /*
  433. * MoutForeign()
  434. *
  435. * This handles the Foreign fields of a message.
  436. */
  437. void MoutForeign(char *dd)
  438.   {
  439.   NetField(dd[0], dd + 1);
  440.  
  441.   }
  442. static int  RWorkBuf[7];
  443. /*
  444. * NowRouteMail()
  445. *
  446. * This function handles outgoing route mail.
  447. */
  448. void NowRouteMail()
  449.   {
  450.   int           rover;
  451.   label temp;
  452.   SYS_FILE      fn;
  453.   extern char *READ_ANY, OverRides;
  454.   if (!netBuf.nbflags.HasRouted)
  455.   return;
  456.   for (rover = 0; rover <= netBuf.nbHiRouteInd; rover++)
  457.     {
  458.     sPrintf(temp, "R%d.%d", thisNet, rover);
  459.     makeSysName(fn, temp, &cfg.netArea);
  460.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  461.       {
  462.       getMsgStr(getNetChar, temp, NAMESIZE);
  463.       getMsgStr(getNetChar, temp, NAMESIZE);
  464.       StartDecode(ReadRoutedDest);
  465.       RCount = SCount = 0;
  466.       while (getMessage(ReadRouted, TRUE, TRUE, TRUE))
  467.         {
  468.         strCpy(msgBuf.mbroom, "Mail");
  469.         NetFormat();
  470.  
  471.         }
  472.       fclose(netMisc);
  473.       unlink(fn);
  474.  
  475.       }
  476.  
  477.     }
  478.   netBuf.nbflags.HasRouted = FALSE;
  479.   netBuf.nbHiRouteInd        = 0;
  480.  
  481.   }
  482. /*
  483. * getNetChar()
  484. *
  485. * This function gets a character from a network temporary file.
  486. */
  487. int getNetChar()
  488.   {
  489.   int c;
  490.   c = fgetc(netMisc);
  491.   if (c == EOF) return -1;
  492.   return c;
  493.  
  494.   }
  495. #define WeServe(x)      SearchList(&Serves, x)
  496. /*
  497. * SepNameSystem()
  498. *
  499. * This will parse an Other Recipient spec.
  500. */
  501. char SepNameSystem(char *string, char *person, char *system, NetBuffer *buf)
  502.   {
  503.   char  *c;
  504.   label domain;
  505.   char dup, work[150];          /* should be sufficient */
  506.   int   slot;
  507.   strCpy(work, string);
  508.   if ((c = strchr(work, '@')) == NULL)
  509.     {
  510.     if (strLen(work) >= NAMESIZE) return BAD_FORMAT;
  511.     strCpy(person, string);
  512.     return NOT_SYSTEM;
  513.  
  514.     }
  515.   *c++ = 0;
  516.   NormStr(work);
  517.   NormStr(c);
  518.   if (strLen(c) >= NAMESIZE * 2 || strLen(work) >= NAMESIZE)
  519.   return BAD_FORMAT;
  520.   strCpy(system, c);
  521.   strCpy(person, work);
  522.   if (buf == NULL) return IS_SYSTEM;    /* very minor cheat - see CTDL.C */
  523.   if ((slot = searchNameNet(c, buf)) != ERROR)
  524.     {
  525.     /* try secondary lists */
  526.     strCpy(system, buf->netName);       /* get "real" name */
  527.     if (buf->nbflags.local)
  528.       {
  529.       return IS_SYSTEM;
  530.  
  531.       }
  532.  
  533.     }
  534.   if (SystemInSecondary(c, domain, &dup))
  535.     {
  536.     if (dup)
  537.       {
  538.       /* oops */
  539.       return (char) ( (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM);
  540.  
  541.       }
  542.     if (strCmpU(domain, cfg.nodeDomain + cfg.codeBuf) == SAMESTRING &&
  543.     (strCmpU(c, cfg.nodeName + cfg.codeBuf) == SAMESTRING ||
  544.     strCmpU(c, UseNetAlias(cfg.nodeName+cfg.codeBuf, TRUE))
  545.     == SAMESTRING))
  546.       {
  547.       printf("Hey, that's this system!\n ");
  548.       return (char)SYSTEM_IS_US;
  549.  
  550.       }
  551.     sPrintf(system, "%s _ %s", c, domain);
  552.     return (char)IS_SYSTEM;
  553.  
  554.     }
  555.   return (char) ( (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM);
  556.  
  557.   }
  558. static label SearchResult;
  559. static char  *SearchTarget, GetAlias;
  560. /*
  561. * SearchSecondary()
  562. *
  563. * This searches a secondary (domain) list for a system.
  564. */
  565. static char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup)
  566.   {
  567.   FILE *fd;
  568.   int  bucket;
  569.   char found, *tab, *c, *tab2;
  570.   char line[90];
  571.   JumpInfo JumpTable[BUCKETCOUNT];
  572.   if ((fd = fopen(secondary, READ_ANY)) == NULL)
  573.   return FALSE;
  574.   fread(line, VERS_SIZE + 1, 1, fd);
  575.   fread(JumpTable, sizeof JumpTable, 1, fd);
  576.   #ifdef IS_MOTOROLA
  577.   for (bucket = 0; bucket < BUCKETCOUNT; bucket++)
  578.   Intel32ToMotorola(&JumpTable[bucket].offset);
  579.   #endif
  580.   bucket = (isdigit(Name[0])) ? Name[0] - '0' :
  581.   toUpper(Name[0]) - 'A' + 10;
  582.   fseek(fd, JumpTable[bucket].offset, 0);
  583.   found = FALSE;
  584.   do
  585.     {
  586.     *isdup = FALSE;
  587.     if (fgets(line, sizeof line, fd) == NULL) break;
  588.     if ((tab2 = strchr(line, '\n')) != NULL)
  589.     *tab2 = 0;
  590.     if (strlen(line) == 0)
  591.       {
  592.       break;
  593.  
  594.       }
  595.     if (line[0] <= ' ')
  596.       {
  597.       switch (line[0])
  598.         {
  599.         case DUP:
  600.         *isdup = TRUE;
  601.         break;
  602.         default: printf("Ooop!");
  603.         break;
  604.  
  605.         }
  606.       c = line + 1;
  607.  
  608.       }
  609.     else c = line;
  610.     tab = strchr(c, '\t');
  611.     *tab++ = 0;
  612.     if (strCmpU(c, Name) == 0)
  613.     found = TRUE;
  614.     if (strCmpU(c, Name) > 0) break;
  615.  
  616.     }
  617.   while (!found);
  618.   if (found)
  619.     {
  620.     if ((tab2 = strchr(tab, '\t')) != NULL)
  621.     *tab2++ = 0;
  622.     strCpy(Domain, tab);
  623.     if (tab2 != NULL)    /* alias?  Copy it into search string */
  624.     strCpy(Name, tab2);
  625.  
  626.     }
  627.   fclose(fd);
  628.   return found;
  629.  
  630.   }
  631. extern VirtualRoom *VRoomTab;
  632. extern VirtNet     *VirtNetList;
  633. extern char VirtualInUse;
  634. extern int  VirtSize, VNetSize;
  635. /*
  636. * MODoVirtuals()
  637. *
  638. * This sends rooms to another system, if needed.
  639. */
  640. void MODoVirtuals()
  641.   {
  642.   int rover,  x;
  643.   if (!VirtualInUse) return ;
  644.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  645.     {
  646.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  647.     if (x >= VirtSize || x < 0 || !VRoomInuse(x))
  648.     VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  649.     if (VirtNetList[thisNet].VirtList[rover].WhichVirt != -1)
  650.       {
  651.       SendVirtual(rover, NULL, NULL, NULL);
  652.  
  653.       }
  654.  
  655.     }
  656.  
  657.   }
  658. /*
  659. * SendVirtual()
  660. *
  661. * This manages sending a room to another system.
  662. */
  663. int SendVirtual(int VirtIndex, char *d1, char *d2, char *d3)
  664.   {
  665.   int   VirtNo, count;
  666.   MSG_NUMBER StartMsg;
  667.   VirtNo = VirtNetList[thisNet].VirtList[VirtIndex].WhichVirt;
  668.   /* Send all the new LD messages received */
  669.   StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LDSent;
  670.   count = ThrowAll(VirtNo, LD_DIR, StartMsg, VRoomTab[VirtNo].vrHiLD,
  671.   VRoomTab[VirtNo].vrName);
  672.   VirtNetList[thisNet].VirtList[VirtIndex].LDSent =
  673.   VRoomTab[VirtNo].vrHiLD;
  674.   if (VirtNetList[thisNet].VirtList[VirtIndex].mode != PEON)
  675.     {
  676.     StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LocSent;
  677.     count += ThrowAll(VirtNo, LOCAL_DIR, StartMsg,
  678.     VRoomTab[VirtNo].vrHiLocal, VRoomTab[VirtNo].vrName);
  679.     VirtNetList[thisNet].VirtList[VirtIndex].LocSent =
  680.     VRoomTab[VirtNo].vrHiLocal;
  681.  
  682.     }
  683.   VRoomTab[VirtNo].vrChanged |= SENT_DATA;
  684.   return count;
  685.  
  686.   }
  687. /*
  688. * ThrowAll()
  689. *
  690. * This sends a virtual room to another system.
  691. */
  692. int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  693. char *room)
  694.   {
  695.   MSG_NUMBER  rover;
  696.   int           count=0;
  697.   char  fn[100];
  698.   extern char *READ_ANY;
  699.   extern PROTO_TABLE Table[];
  700.   extern int    TransProtocol;
  701.   for (rover = start + 1; rover <= end; rover++)
  702.     {
  703.     CreateVAName(fn, which, distance, rover);
  704.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  705.       {
  706.       while (getMessage(getNetChar, TRUE, TRUE, TRUE))
  707.         {
  708.         count++;
  709.         strCpy(msgBuf.mbroom, room);
  710.         NetFormat();
  711.  
  712.         }
  713.       fclose(netMisc);
  714.  
  715.       }
  716.  
  717.     }
  718.   return count;
  719.  
  720.   }
  721. void Intel32ToMotorola(UNS_32 *val)
  722.   {
  723.   unsigned long temp;
  724.   temp = *val;
  725.   *val = ((ULONG)(temp & 0xff) << 24) + ((ULONG)(temp & 0xff00) << 8) +
  726.   ((ULONG)(temp & 0xff0000) >> 8) + ((ULONG)(temp &0xff000000) >> 24);
  727.  
  728.   }
  729.  
  730.  
  731. /*
  732.  * HandleMail
  733.  *
  734.  * This function handles putting mail into the file.
  735.  */
  736. char HandleMail(int net, NetBuffer *nbuf)
  737. {
  738.     struct netMLstruct  buf;
  739.     label           temp;
  740.     SYS_FILE        fn;
  741.     FILE            *mail;
  742.     int         msgcount = 0;
  743.  
  744.     if (nbuf->nbflags.normal_mail) {
  745.         sprintf(temp, "%d.ml", net);
  746.         makeSysName(fn, temp, &cfg.netArea);
  747.         if ((mail = fopen(fn, READ_ANY)) == NULL) {
  748.             printf("WARNING: Couldn't open %s for mail delivery to %s.\n",
  749.                         fn, nbuf->netName);
  750.         }
  751.         else {
  752.             while (getMLNet(mail, buf))
  753.                 if (FindMessage(buf.ML_loc, buf.ML_id)) {
  754.                     strcpy(msgBuf.mbroom, "Mail");
  755.                     if (net != thisNet) {
  756.                         sprintf(msgBuf.mbaddr,
  757.                             "%s _ %s",
  758.                             nbuf->netName,
  759.                             nbuf->netId);
  760.                         splitF( netLog,
  761.                             "Routing mail to %s\n",
  762.                             nbuf->netName);
  763.  
  764.                     }
  765.                     NetFormat();
  766.                     msgcount++;
  767.                 }
  768.  
  769.             fclose(mail);
  770.             unlink(fn);     /* kill mail file */
  771.         }
  772.         nbuf->nbflags.normal_mail = FALSE;
  773.     }
  774.     return TRUE;
  775. }
  776.  
  777.  
  778. void NowDomainMail()
  779. {
  780.     char EatDomainMail(char *, char *, char );
  781.  
  782.     UtilDomainOut(EatDomainMail, FALSE);
  783. }
  784.  
  785. char EatDomainMail(char *name, char *domain, char LocalCheck)
  786. {
  787.     label temp;
  788.  
  789.     if ((netMisc = safeopen(name, READ_ANY)) != NULL) {
  790.         getMsgStr(getNetChar, temp, NAMESIZE);
  791.         getMsgStr(getNetChar, temp, NAMESIZE);
  792.  
  793.         StartDecode(ReadRoutedDest);
  794.         RCount = SCount = 0;
  795.         while (getMessage(ReadRouted, TRUE, TRUE, TRUE)) {
  796.             sprintf(msgBuf.mbaddr, "%s _ %s", temp, domain);
  797.             NetFormat();
  798.             splitF(netLog, "Routing mail to %s _ %s\n", temp, domain);
  799.         }
  800.         fclose(netMisc);
  801.         unlink(name);
  802.     }
  803.     return GOOD_SEND;
  804. }
  805.  
  806.  
  807. int UtilDomainOut(char (*f)(char *name, char *domain, char LocalCheck),
  808.                         char LocalCheck)
  809. {
  810.     DO_Args args;
  811.     void SendDomainMail();
  812.  
  813.     args.count = 0;
  814.     args.fn = f;
  815.     args.lc = LocalCheck;
  816.     RunListA(&DomainMap, SendDomainMail, &args);
  817.     return args.count;
  818. }
  819.